<template>
	<view class="search">
		<template v-if="list.length > 0">
			<block v-for="(item, index) in list" :key="index"><index-list :item="item" :index="index"></index-list></block>
			<!-- 上拉刷新 -->
			<load-more :loadtext="loadtext"></load-more>
		</template>
		<template v-else-if="issearch && list.length < 1">
			<no-thing :nothing="!list.length > 0"></no-thing>
		</template>
	</view>
</template>

<script>
import indexList from '../../components/index/index-list.vue';
import loadMore from '../../components/common/load-more.vue';
import noThing from '../../components/index/no-thing.vue';
export default {
	data() {
		return {
			issearch: false,
			loadtext: '上拉加载更多',
			searchtext: '',
			list: []
		};
	},
	// 监听原生标题导航按钮点击事件
	onNavigationBarButtonTap(ev) {
		if (ev.index === 0) {
			uni.navigateBack({
				delta: 1,
				animationType: 'slide-out-left'
			});
		}
	},
	// 监听点击搜索按钮事件
	onNavigationBarSearchInputChanged(ev) {
		this.searchtext = ev.text
	},
	// 监听点击软键盘搜索按钮事件
	onNavigationBarSearchInputConfirmed(ev) {
		if(ev.text){
			this.getdata()
			uni.hideKeyboard()
		}
	},
	// 监听页面触底事件
	onReachBottom() {
		this.loadmore()
	},
	// 监听页面下拉刷新加载
	onPullDownRefresh() {
		this.getdata()
		uni.stopPullDownRefresh()
	},
	methods: {
		// 搜索事件
		getdata(){
			uni.showLoading()
			// 请求服务器 post keyword:val
			setTimeout(()=> {
				let arr = [
				
						{
							userpic: '../../static/demo/userpic/12.jpg',
							username: '昵称',
							isguanzhu: false,
							title: '我是标题',
							type: 'img', // img: 图文， video：视频
							titlepic: '../../static/demo/datapic/11.jpg',
							infonum: {
								state: 0, // 没有操作， 1、：顶， 2、：踩
								dingnum: 11,
								cainum: 11
							},
							commentnum: 20,
							sharenum: 10
						},
						{
							userpic: '../../static/demo/userpic/12.jpg',
							username: '昵称',
							isguanzhu: true,
							title: '我是标题',
							type: 'video', // img: 图文， video：视频
							titlepic: '../../static/demo/datapic/11.jpg',
							playnum: '20w',
							long: '2:47',
							infonum: {
								state: 1, // 没有操作， 1、：顶， 2、：踩
								dingnum: 11,
								cainum: 11
							},
							commentnum: 20,
							sharenum: 10
						}
				]
				this.list = arr
				this.issearch = true
				uni.hideLoading()
			}, 2000)
		},
		loadmore(){
			this.loadtext = "上拉加载更多";
			if(this.loadtext != "上拉加载更多"){
				return;
			}
			this.loadtext = "加载中...";
			uni.showLoading({
				title:"加载中...",
				mask:true,
				success: () => {
					let obj = {
						userpic: "../../static/demo/userpic/12.jpg",
						username: "昵称",
						isguanzhu: true,
						title: "我是标题",
						type: "video",// img: 图文， video：视频
						titlepic:"../../static/demo/datapic/11.jpg",
						playnum:"20w",
						long: "2:47",
						infonum: {
							state: 1, // 没有操作， 1、：顶， 2、：踩
							dingnum: 11,
							cainum: 11,
						},
						commentnum: 20,
						sharenum: 10
					};
					setTimeout(() => {
						this.list.push(obj)
						uni.hideLoading()
						this.loadtext = "上拉加载更多"
					}, 1000);
				}
			})
		}
	},
	components: {
		indexList,
		loadMore,
		noThing
	}
};
</script>

<style scoped lang="scss">
.search {
	padding: 10upx 20upx;
}
</style>
